/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NameVideo.java
 *
 * Created on 24-ene-2012, 17:13:52
 */
package Vista.configuracion;

import Grabacion.RecAudioOnly;
import Grabacion.RecordAudio;
import Grabacion.VideoTest;
import Persistencia.*;
import Vista.Calibrar.Calibrar;
import Vista.panel.PnlDibujo;
import com.enterprisedt.net.ftp.FileTransferClient;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;

/**
 *
 * @author Jhon Jairo
 */
public class NameVideo extends javax.swing.JFrame {

    public static String name;
    private boolean recPc = false;
    private boolean recServer = false;
    private User currentUser;
    private String courseSelected;

    /**
     * Creates new form NameVideo
     */
    public NameVideo() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        try {
            UIManager.setLookAndFeel(new NimbusLookAndFeel());
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
        }
//        this.setLocationRelativeTo(null);
        initComponents();
        jLabelInfo.setVisible(false);
        jlabelUsername.setVisible(false);
        jLabelPassword.setVisible(false);
        jTextFieldUsername.setVisible(false);
        jPasswordFieldPassword.setVisible(false);
        jButtonIngresar.setVisible(false);
        jComboBoxCourse.setVisible(false);
        jButtonSelectCourse.setVisible(false);
        jCheckBoxAudio.setVisible(false);
        nameVideoLabel.setVisible(false);
        nameVideoText.setVisible(false);
        jTextAreaComent.setVisible(false);
        jLabel2.setVisible(false);
        jScrollPane1.setVisible(false);
        okButton.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nameVideoText = new javax.swing.JTextField();
        nameVideoLabel = new javax.swing.JLabel();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jLabelTitle = new javax.swing.JLabel();
        jCheckRecServer = new javax.swing.JCheckBox();
        jCheckRecPc = new javax.swing.JCheckBox();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jlabelUsername = new javax.swing.JLabel();
        jTextFieldUsername = new javax.swing.JTextField();
        jLabelPassword = new javax.swing.JLabel();
        jPasswordFieldPassword = new javax.swing.JPasswordField();
        jButtonIngresar = new javax.swing.JButton();
        jLabelInfo = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaComent = new javax.swing.JTextArea();
        jCheckBoxAudio = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JSeparator();
        jComboBoxCourse = new javax.swing.JComboBox();
        jButtonSelectCourse = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        nameVideoLabel.setText("Nombre: ");

        okButton.setText("Aceptar");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancelar");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        jLabelTitle.setText("Grabar Video");

        jCheckRecServer.setText("almacenar en el servidor");

        jCheckRecPc.setText("Almacenar en el computador");

        jlabelUsername.setText("Username:");

        jLabelPassword.setText("Password");

        jPasswordFieldPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPasswordFieldPasswordActionPerformed(evt);
            }
        });

        jButtonIngresar.setText("Ingresar");
        jButtonIngresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonIngresarActionPerformed(evt);
            }
        });

        jLabelInfo.setForeground(new java.awt.Color(204, 0, 0));
        jLabelInfo.setText("Log");

        jLabel2.setText("Comentario: ");

        jTextAreaComent.setColumns(20);
        jTextAreaComent.setRows(5);
        jScrollPane1.setViewportView(jTextAreaComent);

        jCheckBoxAudio.setText("Solo grabar Audio");

        jButton1.setText("Seleccionar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButtonSelectCourse.setText("Seleccionar");
        jButtonSelectCourse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSelectCourseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1)
            .addComponent(jSeparator2)
            .addComponent(jSeparator4)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(okButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(cancelButton)
                .addGap(33, 33, 33))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabelInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCheckRecServer)
                                    .addComponent(jCheckRecPc)
                                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(94, 94, 94)
                                        .addComponent(jButtonIngresar, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlabelUsername)
                                            .addComponent(jLabelPassword))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jTextFieldUsername, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                                            .addComponent(jPasswordFieldPassword)))))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jComboBoxCourse, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(26, 26, 26)
                                .addComponent(jButtonSelectCourse))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(nameVideoLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(nameVideoText, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jCheckBoxAudio)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(87, 87, 87)
                        .addComponent(jLabelTitle)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckRecServer)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckRecPc)
                .addGap(5, 5, 5)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlabelUsername)
                    .addComponent(jTextFieldUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelPassword)
                    .addComponent(jPasswordFieldPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonIngresar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxCourse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonSelectCourse))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabelInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameVideoLabel)
                    .addComponent(nameVideoText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBoxAudio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(46, 46, 46)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton)
                    .addComponent(cancelButton))
                .addGap(77, 77, 77))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
//
    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        //****Configura Interfaz Inicial********//
        jLabelInfo.setVisible(false);
        Settings.finalJlabel.setVisible(false);
        jPasswordFieldPassword.setText("");
        jComboBoxCourse.removeAllItems();
        jCheckRecPc.setVisible(true);
        jCheckRecServer.setVisible(true);
        jButton1.setVisible(true);
        jScrollPane1.setVisible(false);
        nameVideoLabel.setVisible(false);
        nameVideoText.setVisible(false);
        jTextAreaComent.setVisible(false);
        jLabel2.setVisible(false);
        System.out.println("antes de nada" + PnlDibujo.screenS);
        System.out.println("recserver" + recServer);
        //*******Si se selecciona Almacenar en el servidor********//
        if (recServer) {
            //
            VideoJpaController vjpa = new VideoJpaController();
            CourseJpaController cjpa = new CourseJpaController();
            AudioJpaController ajpa = new AudioJpaController();
            ImageJpaController ijpa = new ImageJpaController();
            try {
                //busca curso dependiendo de el q se selecciono en el combobox
                Course c = cjpa.findCourseByName(courseSelected);
                System.out.println("aca----->" + c.getNombre());
                //decide si va a grabar solo audio
                if (jCheckBoxAudio.isSelected()) {
                    Audio a = new Audio(null, nameVideoText.getText().toString(), "http://192.168.190.122:8080/pizarraweb/Audio/"
                            + nameVideoText.getText().toString() + ".mp3", jTextAreaComent.getText().toString(), c.getId());
                    ajpa.create(a);
                    name = nameVideoText.getText();
                    System.out.println("name=" + name);
                    RecAudioOnly.f = new File(NameVideo.name.toString() + ".mp3");
                    RecAudioOnly recAudioOnlysa = new RecAudioOnly();
                    System.out.println("estoy Grabando audio nomas con servidor");
                    Settings.nm.setVisible(false);
                    Settings.jProgressBarSend.setVisible(true);
                    Settings.jProgressBarSend.setIndeterminate(true);
                    okButton.setVisible(false);
                    jCheckBoxAudio.setVisible(false);
                    //si no va a grabar audio entonces decide si es un pantallazo
                } else if (PnlDibujo.screenS) {
                    jLabelTitle.setText("Tomando Pantallazo");
                    Persistencia.Image i = new Persistencia.Image(null, nameVideoText.getText().toString(), "http://192.168.190.122:8080/pizarraweb/Images/"
                            + nameVideoText.getText().toString() + ".jpg", jTextAreaComent.getText().toString(), c.getId());
                    ijpa.create(i);
                    Settings.nm.setVisible(false);
                    Calibrar.set.setVisible(false);
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(PnlDibujo.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    if (Settings.frm.isVisible()) {
                        System.out.println("entra al if***imagenserver");
                        BufferedImage pantalla = null;
                        try {
                            pantalla = new Robot().createScreenCapture(
                                    new Rectangle(
                                    Toolkit.getDefaultToolkit().getScreenSize()));
                        } catch (AWTException ex) {
                            Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        File file = new File(nameVideoText.getText().toString() + ".jpg");
                        try {
                            ImageIO.write(pantalla, "jpg", file);
                        } catch (IOException ex) {
                            Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        Settings.frm.setVisible(false);

                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(PnlDibujo.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        try {
                            FileTransferClient ftp = new FileTransferClient();
                            ftp.setRemoteHost("192.168.190.122");
                            ftp.setUserName("pizarra");
                            ftp.setPassword("pizarra");
                            ftp.connect();

                            ftp.uploadFile(nameVideoText.getText().toString() + ".jpg", "/pizarraweb/Images/" + nameVideoText.getText().toString() + ".jpg");
                            ftp.disconnect();
                            System.out.println("imagen Creada...");
                            File imagen = new File(nameVideoText.getText().toString() + ".jpg");
                            imagen.delete();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        Calibrar.set.setVisible(true);
                        PnlDibujo.screenS = false;
                        recPc = false;
                        recServer = false;
                        jLabelInfo.setVisible(false);
                        jTextFieldUsername.setText("");
                        jPasswordFieldPassword.setText("");
                        jComboBoxCourse.removeAllItems();
                        jCheckRecPc.setVisible(true);
                        jCheckRecServer.setVisible(true);
                        jButton1.setVisible(true);
                        jTextAreaComent.setText("");
                        nameVideoText.setText("");
                    }
                    //finalmente si no decide grabar audio entonces graba video
                } else {
                    System.out.println("grabar video......");
                    Video v = new Video(null, nameVideoText.getText().toString(), "http://192.168.190.122:8080/pizarraweb/Videos/"
                            + nameVideoText.getText().toString() + ".mp4", jTextAreaComent.getText().toString(), c.getId());
                    vjpa.create(v);
                    name = nameVideoText.getText().toString();
                    System.out.println("name=" + name);
                    Settings.nm.setVisible(false);
                    Settings.setState(true);
                    VideoTest.isRec = true;
                    if (!(VideoTest.RecordVThread.getState().equals(Thread.State.RUNNABLE))) {
                        VideoTest.RecordVThread.start();
                    }
                    new RecordAudio().tD.start();
                    Settings.jProgressBarSend.setVisible(true);
                    Settings.jProgressBarSend.setIndeterminate(true);
                    Settings.finalJlabel.setVisible(false);
                    Settings.nm.setVisible(false);
                    okButton.setVisible(false);
                    jCheckBoxAudio.setVisible(false);
                }
            } catch (javax.persistence.NoResultException ex) {
                //recServer = false;
            }
            //**si se selecciono almacenar en el computador
        } else if (recServer == false) {
            //si decide solo capturar un pantallazo
            if (PnlDibujo.screenS) {
                jCheckBoxAudio.setVisible(false);
                Settings.nm.setVisible(false);
                Calibrar.set.setVisible(false);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ex) {
                    Logger.getLogger(PnlDibujo.class.getName()).log(Level.SEVERE, null, ex);
                }
                if (Settings.frm.isVisible()) {
                    System.out.println("entra al if***image");
                    BufferedImage pantalla = null;
                    try {
                        pantalla = new Robot().createScreenCapture(
                                new Rectangle(
                                Toolkit.getDefaultToolkit().getScreenSize()));
                    } catch (AWTException ex) {
                        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    File file = new File(nameVideoText.getText().toString() + ".jpg");
                    try {
                        ImageIO.write(pantalla, "jpg", file);
                    } catch (IOException ex) {
                        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    Settings.frm.setVisible(false);

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(PnlDibujo.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    Calibrar.set.setVisible(true);
                    PnlDibujo.screenS = false;
                    recPc = false;
                    recServer = false;
                    jLabelInfo.setVisible(false);
                    jTextFieldUsername.setText("");
                    jPasswordFieldPassword.setText("");
                    jComboBoxCourse.removeAllItems();
                    jCheckBoxAudio.setVisible(false);
                    jCheckRecPc.setVisible(true);
                    jCheckRecServer.setVisible(true);
                    jButton1.setVisible(true);
                    jTextAreaComent.setText("");
                    nameVideoText.setText("");
                }
                //si decide grabar solo video
            } else if (!jCheckBoxAudio.isSelected()) {
                System.out.println("sin seleccionar nada");
                name = nameVideoText.getText();
                System.out.println("name=" + name);
                Settings.nm.setVisible(false);
                Settings.setState(true);
                VideoTest.isRec = true;
                if (!(VideoTest.RecordVThread.getState().equals(Thread.State.RUNNABLE))) {
                    VideoTest.RecordVThread.start();
                }
                new RecordAudio();
                Settings.createJlabel.setVisible(true);
                Settings.finalJlabel.setVisible(false);
                Settings.nm.setVisible(false);
                recPc = false;
                recServer = false;
                jLabelInfo.setVisible(false);
                jTextFieldUsername.setText("");
                jPasswordFieldPassword.setText("");
                jComboBoxCourse.removeAllItems();
                jCheckRecPc.setVisible(true);
                jCheckRecServer.setVisible(true);
                jButton1.setVisible(true);
                jTextAreaComent.setText("");
                nameVideoText.setText("");
                okButton.setVisible(false);
                jCheckBoxAudio.setVisible(false);
                okButton.setVisible(false);
                jCheckBoxAudio.setVisible(false);
                //si decide grabar audio
            } else {
                name = nameVideoText.getText();
                System.out.println("name=" + name);
                RecAudioOnly.f = new File(NameVideo.name.toString() + ".mp3");
                RecAudioOnly recAudioOnly = new RecAudioOnly();
                System.out.println("estoy Grabando audio nomas sin servidor");
                Settings.nm.setVisible(false);
                okButton.setVisible(false);
                jCheckBoxAudio.setVisible(false);
            }
        }
        Calibrar.set.setVisible(true);
    }//GEN-LAST:event_okButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        Settings.nm.setVisible(false);
        Settings.recLabelV.setVisible(true);
        Settings.stopLabelV.setVisible(false);
        Settings.createJlabel.setVisible(false);
        Settings.finalJlabel.setVisible(false);
        recPc = false;
        recServer = false;
        jLabelInfo.setVisible(false);
        jTextFieldUsername.setText("");
        jPasswordFieldPassword.setText("");
        jComboBoxCourse.removeAllItems();
        jCheckRecPc.setVisible(true);
        jCheckRecServer.setVisible(true);
        jButton1.setVisible(true);
        jScrollPane1.setVisible(false);
        jTextAreaComent.setText("");
        nameVideoText.setText("");
        jCheckBoxAudio.setVisible(false);
        nameVideoLabel.setVisible(false);
        nameVideoText.setVisible(false);
        nameVideoText.setText("");
        jTextAreaComent.setVisible(false);
        jLabel2.setVisible(false);
        PnlDibujo.screenS = false;
        okButton.setVisible(false);
        Calibrar.set.setVisible(true);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void jPasswordFieldPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordFieldPasswordActionPerformed
    }//GEN-LAST:event_jPasswordFieldPasswordActionPerformed

    private void jButtonIngresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIngresarActionPerformed
        if (jCheckRecServer.isSelected()) {
            UserJpaController ujpa = new UserJpaController();
            CourseJpaController cjpa = new CourseJpaController();
            try {
                currentUser = ujpa.findUsers(jTextFieldUsername.getText().toString(), jPasswordFieldPassword.getText().toString());
                jLabelInfo.setForeground(Color.GREEN);
                jLabelInfo.setText("Logueado... " + currentUser.getName());
                jLabelInfo.setVisible(true);
                jTextFieldUsername.setVisible(false);
                jPasswordFieldPassword.setVisible(false);
                jlabelUsername.setVisible(false);
                jLabelPassword.setVisible(false);
                jButtonIngresar.setVisible(false);
                jCheckRecPc.setVisible(false);
                jCheckRecServer.setVisible(false);
                jButton1.setVisible(false);
                List<Course> courseList = cjpa.findGroupByIdTeacher(currentUser.getId());
                for (int i = 0; i < courseList.size(); i++) {
                    jComboBoxCourse.addItem(courseList.get(i).getNombre());
                }
                jComboBoxCourse.setVisible(true);
                jComboBoxCourse.getSelectedItem();
                jButtonSelectCourse.setVisible(true);
                recServer = true;
            } catch (javax.persistence.NoResultException ex) {
                jLabelInfo.setForeground(Color.red);
                jLabelInfo.setText("Error, login o password incorrectos");
                jLabelInfo.setVisible(true);
                recServer = false;
            }
        }
    }//GEN-LAST:event_jButtonIngresarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        jLabelInfo.setVisible(false);
        jTextFieldUsername.setText("");
        jPasswordFieldPassword.setText("");
        jComboBoxCourse.removeAllItems();
        jCheckRecPc.setVisible(true);
        jCheckRecServer.setVisible(true);
        jButton1.setVisible(true);
        jScrollPane1.setVisible(false);
        jTextAreaComent.setText("");
        nameVideoText.setText("");
        jCheckBoxAudio.setVisible(false);
        nameVideoLabel.setVisible(false);
        nameVideoText.setVisible(false);
        nameVideoText.setText("");
        jTextAreaComent.setVisible(false);
        jLabel2.setVisible(false);
        okButton.setVisible(false);
        if (jCheckRecServer.isSelected()) {
            jlabelUsername.setVisible(true);
            jLabelPassword.setVisible(true);
            jTextFieldUsername.setVisible(true);
            jPasswordFieldPassword.setVisible(true);
            jButtonIngresar.setVisible(true);
            jSeparator1.setVisible(true);
        } else {
            nameVideoLabel.setVisible(true);
            okButton.setVisible(true);
            if (PnlDibujo.screenS) {
                jCheckBoxAudio.setVisible(false);

            } else {
                jCheckBoxAudio.setVisible(true);
            }
            nameVideoText.setVisible(true);
            jlabelUsername.setVisible(false);
            jLabelPassword.setVisible(false);
            jTextFieldUsername.setVisible(false);
            jPasswordFieldPassword.setVisible(false);
            jButtonIngresar.setVisible(false);
            recServer = false;
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButtonSelectCourseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectCourseActionPerformed
        courseSelected = jComboBoxCourse.getSelectedItem().toString();
        jLabelInfo.setForeground(Color.green);
        jLabelInfo.setText("Curso seleccionado: " + courseSelected);
        jComboBoxCourse.setVisible(false);
        jButtonSelectCourse.setVisible(false);
        jSeparator1.setVisible(false);
        okButton.setVisible(true);
        if (PnlDibujo.screenS) {
            jCheckBoxAudio.setVisible(false);
            nameVideoLabel.setVisible(true);
            nameVideoText.setVisible(true);
            jScrollPane1.setVisible(true);
            jTextAreaComent.setVisible(true);
            jLabel2.setVisible(true);
        } else {
            jCheckBoxAudio.setVisible(true);
            nameVideoLabel.setVisible(true);
            nameVideoText.setVisible(true);
            jScrollPane1.setVisible(true);
            jTextAreaComent.setVisible(true);
            jLabel2.setVisible(true);
        }
    }//GEN-LAST:event_jButtonSelectCourseActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonIngresar;
    private javax.swing.JButton jButtonSelectCourse;
    public static javax.swing.JCheckBox jCheckBoxAudio;
    public static javax.swing.JCheckBox jCheckRecPc;
    public static javax.swing.JCheckBox jCheckRecServer;
    private javax.swing.JComboBox jComboBoxCourse;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelInfo;
    private javax.swing.JLabel jLabelPassword;
    public static javax.swing.JLabel jLabelTitle;
    private javax.swing.JPasswordField jPasswordFieldPassword;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JTextArea jTextAreaComent;
    private javax.swing.JTextField jTextFieldUsername;
    private javax.swing.JLabel jlabelUsername;
    private javax.swing.JLabel nameVideoLabel;
    public static javax.swing.JTextField nameVideoText;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables
}
